<script setup>
import { ref } from 'vue'
import HomePanel from './HomePanel.vue'

// 本地模拟的“商城上新”数据（替换为你的本地图片路径）
const newGoodsList = ref([
  { 
    id: 1, 
    name: "新鲜苹果", 
    price: "9.9", 
    picture: new URL('@/assets/images/apple.png', import.meta.url).href 
  },
  { 
    id: 2, 
    name: "有机蔬菜", 
    price: "15.8", 
    picture: new URL('@/assets/images/vegetable.png', import.meta.url).href 
  },
  { 
    id: 3, 
    name: "进口牛奶", 
    price: "29.9", 
    picture: new URL('@/assets/images/milk.png', import.meta.url).href 
  },
  { 
    id: 4, 
    name: "全麦面包", 
    price: "12.5", 
    picture: new URL('@/assets/images/bread.png', import.meta.url).href 
  }
])
</script>

<template>
 <HomePanel title="商城上新" subTitle="新鲜出炉 品质靠谱">
    <template #main>
      <ul class="goods-list">
        <li v-for="item in newGoodsList" :key="item.id">
          <RouterLink :to="`/detail/${item.id}`">
            <img :src="item.picture" :alt="item.name" />
            <p class="name">{{ item.name }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul>
    </template>
  </HomePanel>
</template>

<style scoped lang='less'>
// 定义Less变量
@priceColor: #ff4d4f; // 可以根据你的设计调整这个颜色值

.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    transition: all 0.5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    }

    img {
      width: 306px;
      height: 306px;
      object-fit: cover; /* 确保图片填充容器 */
    }

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .price {
      color: @priceColor; // 使用Less变量
    }
  }
}
</style>
